layui.use(['form','layer','upload','admin','layedit'],function(){
	   var form = layui.form
       layer = parent.layer === undefined ? layui.layer : top.layer,
       $ = layui.jquery,
       laydate = layui.laydate,
       laytpl = layui.laytpl,
       admin = layui.admin,
	   
       $(document).on('click', '#btnRm', function(data) {
    	   $(this).parent().parent().empty();
    	   $(this).children("div").empty();
       });
	   
	   $(document).on('click', '#btnAdd', function(data) {
		   var str = '<div class="layui-inline"><label class="layui-form-labels">字典内容：</label><div class="layui-input-inline">';
		       str += '<input type="tel" name="dictionaryData" id="dictionaryData" lay-verify="required" autocomplete="off" class="layui-input"></div>';
			   str += '<div class="layui-form-mid layui-word-aux">';
			   str += '<button type="button" class="layui-btn" style="background-color: red;" lay-filter="btnRm" id="btnRm">删除</button>';
			   str += '</div></div>';
		   $("#new").append(str);
	   });
       
	    // 表单提交事件
	    form.on('submit(btnSubmit)', function (data) {
	    	var dictionaryData = '';
	    	$('input[id="dictionaryData"]').each(function (){
	    		var val = $(this).val();
	    		if(dictionaryData == ''){
	    			dictionaryData += val;
	    		}else{
	    			dictionaryData +=","+val;
	    		}
	    	});
	    	var dictionaryName = $("#dictionaryName").val();
	    	var data = {
	    			dictionaryData: dictionaryData,
	    			dictionaryName:dictionaryName
	    	}
	    	// 异步请求
	    	$.ajax({
	    		url: Feng.ctxPath + "/modular/dictionary/insert",
	    		data: JSON.stringify(data),
	    		type: "post",
	    		contentType: "application/json;charset=UTF-8",
	    		async: false,//关闭异步请求
	    		dataType: "json",
	    		success: function (data) {
	    			if (data.code == 200) {
	    				Feng.success("操作成功！");
	    				//传给上个页面，刷新table用
	    				admin.putTempData('formOk', true);
	    				//关掉对话框
	    				admin.closeThisDialog();
	    			} else {
	    				Feng.success("操作失败！" + data.message);
	    			}
	    		}
	    	,
	    	error: function (data) {
	    		Feng.error("添加失败！" + data.message)
	    	}
	    	});
	    });
	    
});